<template>
  <div>
    <el-container style="padding: 10px 120px 0 120px;">
      <el-header class="homeHeader">
        <div class="title">
          <span>教室无感考勤系统</span>
        </div>
        <!--Dropdown 下拉菜单-->
        <el-dropdown class="userInfo" @command="commandHandler">
          <span class="el-dropdown-link">
            {{user.name}}
            <i><img :src="face"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="userInfo">个人中心</el-dropdown-item>
            <el-dropdown-item command="setting">设置</el-dropdown-item>
            <el-dropdown-item command="logout" divided>注销登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
      <el-divider style="height: 0;"></el-divider>
      <el-container>
        <el-aside style="width: 200px;">
          <el-menu router
                   unique-opened>
            <el-submenu :index="index + ''" v-for="(item, index) in routes"
                        :key="index"
                        v-if="!item.hidden">
              <template slot="title">
                <i :class="item.iconCls" class="homeIcon"></i>
                <span style="font-size: 16px;">{{item.name}}</span></template>
              <el-menu-item :index="children.path"
                            style="font-size: 14px;"
                            v-for="(children, indexj) in item.children"
                            :key="indexj">
                {{children.name}}
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <!--Breadcrumb 面包屑-->
          <el-breadcrumb v-if="this.$router.currentRoute.path !== '/home'"
                         separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
          </el-breadcrumb>
          <div v-if="this.$router.currentRoute.path === '/home'" class="homeWelcome">
            欢迎来到教室无感考勤系统！
          </div>
          <router-view class="homeRouterView"/>
        </el-main>
      </el-container>
    </el-container>
    <el-footer class="el-footer">
      <div class="footerWrapper">
        <div class="footer">
          <div class="webInfo">
            <div style="font-size: medium;
                        margin-bottom: 20px;
                        color: dimgrey">
              网站信息
            </div>
            <div>
              <span>网站：教室无感考勤系统</span>
            </div>
            <div>
              <span>指导教师：谢斌</span>
            </div>
            <div>
              <span>作者：汪子洋</span>
            </div>
            <div>
              <span>学号：0918160224</span>
            </div>
            <div>
              <span>学校：中南大学</span>
            </div>
            <div>
              <span>学院：自动化学院</span>
            </div>
            <div>
              <span>专业：智能科学与技术</span>
            </div>
            <div>
              <span>班级：1702</span>
            </div>
          </div>
          <div class="envInfo">
            <div class="envBackEndInfo">
              <div style="font-size: small;
                        margin-bottom: 20px;
                        color: dimgrey">
                <div style="padding: 0;margin: 0;">
                  Environmental Parameters
                </div>
                <div style="padding: 0;margin: 0;">
                  of Back-End
                </div>
              </div>
              <div>
                <span>SpringBoot 2.3.0</span>
              </div>
              <div>
                <span>SpringMVC</span>
              </div>
              <div>
                <span>SpringSecurity</span>
              </div>
              <div>
                <span>MybatisPlus 3.3.1</span>
              </div>
              <div>
                <span>Swagger2 2.7.0</span>
              </div>
              <div>
                <span>jjwt 0.9.0</span>
              </div>
              <div>
                <span>RabbitMQ 2.4.3</span>
              </div>
              <div>
                <span>Redis</span>
              </div>
              <div>
                <span>BaiduApi 4.11.3</span>
              </div>
            </div>
            <div class="envFrontEndInfo">
              <div style="font-size: small;
                        margin-bottom: 20px;
                        color: dimgrey">
                <div style="padding: 0;margin: 0;">
                  Environmental Parameters
                </div>
                <div style="padding: 0;margin: 0;">
                  of Front-End
                </div>
              </div>
              <div>
                <span>vue 2.6.11</span>
              </div>
              <div>
                <span>vuex 3.6.2</span>
              </div>
              <div>
                <span>vue-router 3.2.0</span>
              </div>
              <div>
                <span>axios 0.21.1</span>
              </div>
              <div>
                <span>less 4.1.1</span>
              </div>
              <div>
                <span>element-ui 2.15.1</span>
              </div>
              <div>
                <span>echarts 4.9.0</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-footer>
  </div>
</template>

<script>
  export default {
    name: "Home",
    data() {
      return {
        user: {},
        face: ''
      }
    },
    created() {
      //加载用户信息
      this.getRequest('/admin/info').then(resp => {
        if (resp) {
          this.user = resp;
          //存入sessionStorage中
          window.sessionStorage.setItem('user',JSON.stringify(resp));
          if (this.user.teacherId) {
            this.getRequest('/perinformation/teacher/' + this.user.teacherId).then(resp => {
              if (resp) {
                this.face = 'data:image/jpeg;base64,' + resp.face
              }
            })
          } else {
            this.getRequest('/perinformation/student/' + this.user.studentId).then(resp => {
              if (resp) {
                this.face = 'data:image/jpeg;base64,' + resp.face
              }
            })
          }
        } else {
          this.$message({
            type: 'error',
            message: '用户信息加载失败'
          });
        }
      })
    },
    computed: {
      routes() {
        return this.$store.state.routes
      }
    },
    methods: {
      commandHandler(command) {
        if (command === 'logout') {
          //  MessageBox 弹框 - 确认消息
          this.$confirm('此操作将注销登录, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            //  注销登录
            this.postRequest('/logout')
            //  清空用户信息
            // window.sessionStorage.removeItem('tokenStr')
            // window.sessionStorage.removeItem('user')
            window.sessionStorage.clear()
            //  清空菜单信息，否则下一个用户登录显示的还是上一个用户的菜单
            this.$store.commit('initRoutes', [])
            //  跳转登录页面
            this.$router.replace('/')
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消操作'
            })
          })
        }
      }
    }
  }
</script>

<style>

  .homeHeader {
    background: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
  }

  .title {
    height: auto;
  }

  .title i {
    font-size: 39px;
    color: #409EFF;
    margin-right: 5px;
  }

  .title span {
    font-size: 28px;
    color: #409EFF;
  }

  .homeHeader .userInfo {
    cursor: pointer;
    color: black;
  }

  .homeIcon {
    color: dodgerblue;
    font-size: 16px;
    margin-right: 5px;
  }

  .el-dropdown-link img {
    width: 40px;
    height: 40px;
    border-radius: 20px;
    margin-left: 2px;
  }

  .homeWelcome {
    text-align: center;
    font-size: 30px;
    padding-top: 50px;
  }

  .homeRouterView {
    margin-top: 15px;
  }

  .el-footer {
    padding: 200px 0 0 0;
  }

  .footerWrapper {
    width: 100%;
    height: 400px;
    background-color: #EDF2FC;
  }

  .footer {
    padding: 50px 150px 0 150px;
    display: flex;
    justify-content: space-between;
  }

  .webInfo {
    color: #9093A6;
    font-size: x-small;
    margin-right: 40px;
  }

  .webInfo div {
    margin-bottom: 10px;
  }

  .envInfo {
    display: flex;
  }

  .envBackEndInfo {
    color: #9093A6;
    font-size: x-small;
    margin-right: 40px;
  }

  .envBackEndInfo div {
    margin-bottom: 10px;
  }

  .envFrontEndInfo {
    color: #9093A6;
    font-size: x-small;
  }

  .envFrontEndInfo div {
    margin-bottom: 10px;
  }

  .aside {
    width: 200px;
  }
</style>